import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { Cache } from "../../../cache/Cache";
import { ColorConfig } from "../../../resource/ColorConfig";
import { ItemData } from "../../../resource/info/ItemData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { Language } from "../../../../../extend/language/Language";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ShopConfig } from "../../../resource/ShopConfig";
import { ShopRule } from "../../../rules/ShopRule";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BaseItem } from "../../common/BaseItem";
import { MsgManager } from "../../../manager/MsgManager";
import { HonorShopModule } from "../../../../../modules/HonorShopModule";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { ShopEventName } from "../ShopEventName";
import { CursorManager } from "../../../manager/CursorManager";
import { EffectManager } from "../../../manager/EffectManager";
import { LineBox } from "../../guide/LineBox";
import { TItem } from "../../../../../Message/Db/Tables/TItem";
import { ColorInfo } from "../../../resource/info/ColorInfo";
type int = number;
//class HonorItemRender
    
    export  class HonorItemRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.createChildren();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            super.data = arg1;
            this.shopItemInfo = arg1 as ShopItemInfo;
            if (this.shopItemInfo && this.shopItemInfo.itemInfo) 
            {
                loc1 = this.shopItemInfo.tshopSell.activeOffer;
                if (Cache.instance.shop.isShopMallDiscount && loc1 > 0) 
                {
                    this._price = this.shopItemInfo.tshopSell.activeOffer;
                }
                else 
                {
                    this._price = this.shopItemInfo.tshopSell.price;
                }
                this._priceType = this.shopItemInfo.unit;
                this.itemInfo = this.shopItemInfo.itemInfo.item;
                this._itemLevel = this.itemInfo.itemLevel;
                this.colorInfo = ColorConfig.instance.getItemColor(this.itemInfo.color);
                if (this.colorInfo) 
                {
                    this.colorName = this.colorInfo.color;
                }
                loc2 = new ItemData(this.itemInfo.code);
                this._propImage.itemData = loc2;
                this._propImage.drawNow();
                this._propImage.setAmountLabel("");
                this._isContriShopBuyMsg = false;
                this._nameLabel.htmlText = HTMLUtil.addColor(this.itemInfo.name, this.colorName);
                this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
                if (this._priceImgName == "") 
                {
                    this._unitBitmap.bitmapData = null;
                    this._unitName = GameDefConfig.instance.getEPrictUnitName(this._priceType);
                    if (this._priceType == EPrictUnit._EPriceUnitMerit) 
                    {
                        this._unitName = this._unitName.substr(2);
                    }
                    if (this._priceType == EPrictUnit._EPriceUnitInterHonour) 
                    {
                        this._unitName = Language.getString(74407);
                    }
                    this._unitTxt.text = this._unitName + "：";
                    this._priceTxt.x = this._unitTxt.x + this._unitTxt.textWidth;
                }
                else 
                {
                    this._unitTxt.text = "";
                    this._unitBitmap.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                    this._priceTxt.x = this._unitBitmap.x + this._unitBitmap.width;
                }
                this._priceTxt.text = this._price.toString();
                this.selected = true;
                if (this._priceType == EPrictUnit._EPriceUnitMerit || this._priceType == EPrictUnit._EPriceUnitMagicStone) 
                {
                    if (Cache.instance.role.medalCode > 0) 
                    {
                        if (loc3 = new ItemData(Cache.instance.role.medalCode)) 
                        {
                            this._medalLevel = loc3.itemInfo.item.itemLevel;
                        }
                    }
                    if (this._priceType != EPrictUnit._EPriceUnitMerit) 
                    {
                        if (this._priceType == EPrictUnit._EPriceUnitMagicStone) 
                        {
                            if (loc4 = ShopConfig.instance.getShopItemInfo(loc2.itemCode, ShopRule.ShopMoshiHide)) 
                            {
                                loc5 = loc4.tshopSell.price;
                            }
                            if (this._medalLevel < loc5) 
                            {
                                this.showMask(true);
                            }
                            else 
                            {
                                this.showMask(false);
                            }
                            this.showLineBox(false);
                            if ((loc6 = Cache.instance.shop.gangFightShopBuyLimitInfo) && loc6.isInLimit(loc2.itemCode)) 
                            {
                                this._propImage.setAmountLabel(loc6.getAmountLabel(loc2.itemCode));
                                this.showLineBox(false);
                                this.showMask(false);
                            }
                        }
                    }
                    else 
                    {
                        if (this._medalLevel > 0 && this._itemLevel == this._medalLevel) 
                        {
                            this.showLineBox(true);
                        }
                        else 
                        {
                            this.showLineBox(false);
                        }
                        if (this._price > Cache.instance.role.money.merit) 
                        {
                            this.showMask(true);
                        }
                        else 
                        {
                            this.showMask(false);
                        }
                    }
                }
                else if (this._priceType != EPrictUnit._EPriceUnitArena) 
                {
                    if (this._priceType != EPrictUnit._EPriceUnitCountryContribution) 
                    {
                        if (this._priceType != EPrictUnit._EPriceUnitInterHonour) 
                        {
                            this.showLineBox(false);
                            this.showMask(false);
                        }
                        else 
                        {
                            if (loc9 = Cache.instance.shop.honorShopBuyLimitInfo) 
                            {
                                this._propImage.setAmountLabel(loc9.getAmountLabel(loc2.itemCode));
                            }
                            this.showLineBox(false);
                            this.showMask(false);
                        }
                    }
                    else 
                    {
                        if ((loc8 = Cache.instance.shop.countryContributionShopBuyLimitInfo).isInLimit(loc2.itemCode)) 
                        {
                            this._propImage.setAmountLabel(loc8.getAmountLabel(loc2.itemCode));
                            if (loc8.isFullBuy(loc2.itemCode)) 
                            {
                                this.showMask(true);
                                this._isContriShopBuyMsg = true;
                            }
                            else 
                            {
                                this.showMask(false);
                            }
                        }
                        else 
                        {
                            this.showMask(false);
                        }
                        this.showLineBox(false);
                    }
                }
                else 
                {
                    if (loc7 = Cache.instance.shop.arenaShopBuyLimitInfo) 
                    {
                        this._propImage.setAmountLabel(loc7.getAmountLabel(loc2.itemCode));
                    }
                    this.showLineBox(false);
                    this.showMask(false);
                }
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            ObjCreate.createBg(0, 0, 135, 45, this);
            ObjCreate.createBg(2, 2, 38, 38, this, ImagesConst.PackItemBg);
            this._nameLabel = new GLabel();
            this._nameLabel.x = 45;
            this._nameLabel.y = 5;
            this._nameLabel.height = 40;
            this.addChild(this._nameLabel);
            this._unitTxt = ObjCreate.createTextField("", 45, 22, 50, 20, this, GlobalStyle.textFormat2);
            this._unitTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._priceTxt = ObjCreate.createTextField("", 86, 22, 50, 20, this, GlobalStyle.textFormat2);
            this._priceTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._unitBitmap = new Object /* flash.display.Bitmap */();
            this._unitBitmap.x = 45;
            this._unitBitmap.y = 22;
            this.addChild(this._unitBitmap);
            this._clickSprite = new Object /* flash.display.Sprite */();
            this._clickSprite.graphics.beginFill(16711680, 0);
            this._clickSprite.graphics.drawRect(0, 0, 142, 40);
            this._clickSprite.graphics.endFill();
            this._clickSprite.cacheAsBitmap = true;
            this.addChild(this._clickSprite);
            this._propImage = new BaseItem();
            this._propImage.label = "";
            this._propImage.setSize(32, 32);
            this._propImage.move(5, 5);
            this.addChild(this._propImage);
            return;
        }

        public onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._isEnable) 
            {
                if (this._isContriShopBuyMsg) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(70679));
                }
                return;
            }
            if (HonorShopModule.isBuy) 
            {
                Dispatcher.dispatchEvent(new DataEvent(ShopEventName.ShopItemClick, this.shopItemInfo, false, true));
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this.itemInfo) 
            {
                this.filters = [new Object /* flash.filters.GlowFilter */(3856353, 1, 6, 6, 1, 1, false, false)];
            }
            else 
            {
                this.filters = [];
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._isEnable) 
            {
                return;
            }
            if (HonorShopModule.isBuy) 
            {
                CursorManager.showCursor(CursorManager.BUY);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal  */showLineBox(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (!this._lineBox) 
                {
                    this._lineBox = EffectManager.getLineBox(135, 45, [65280]);
                    this._lineBox.x = 0;
                    this._lineBox.y = 0;
                }
                if (!this.contains(this._lineBox)) 
                {
                    this.addChild(this._lineBox);
                }
            }
            else if (this._lineBox && this.contains(this._lineBox)) 
            {
                this.removeChild(this._lineBox);
                EffectManager.disposeLineBox(this._lineBox);
                this._lineBox = null;
            }
            return;
        }

        /* internal  */showMask(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._clickSprite.graphics.clear();
                this._clickSprite.graphics.beginFill(0, 0.4);
                this._clickSprite.graphics.drawRect(0, 0, 135, 45);
                this._clickSprite.graphics.endFill();
                this._isEnable = false;
            }
            else 
            {
                this._clickSprite.graphics.clear();
                this._isEnable = true;
            }
            return;
        }

        /* internal */ /* var */_clickSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propImage: BaseItem;

        /* internal */ /* var */_unitTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string;

        /* internal */ /* var */_unitName: string="";

        /* internal */ /* var */shopItemInfo: ShopItemInfo;

        /* internal */ /* var */itemInfo: TItem;

        /* internal */ /* var */_itemLevel: int;

        /* internal */ /* var */toAdd: Boolean=true;

        /* internal */ /* var */colorInfo: ColorInfo;

        /* internal */ /* var */colorName: string;

        /* internal */ /* var */_isEnable: Boolean=true;

        /* internal */ /* var */_medalItemData: ItemData;

        /* internal */ /* var */_medalLevel: int;

        /* internal */ /* var */_isContriShopBuyMsg: Boolean;
    }
